# -*- coding: utf-8 -*-
"""
Created on Sat Mar 27 09:24:25 2021

@author: Apple
"""
# import requests
# from bs4 import BeautifulSoup

# r = requests.get('https://book.douban.com/subject/4913064/comments/')
# soup = BeautifulSoup(r.text,'lxml')
# pattern = soup.find_all('span','short')
# for item in pattern:
#     print(item.string)



# from bs4 import BeautifulSoup
# markup = '<p class = "title"><b>The Little Prince</b></p>'
# soup = BeautifulSoup(markup,'lxml')

import requests
from bs4 import BeautifulSoup
import re

headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36'}
r = requests.get('https://book.douban.com/subject/4913064/comments/',headers=headers)
soup = BeautifulSoup(r.text,'lxml')
pattern = soup.find_all('span','short')
for item in pattern:
    print(item.string)
pattern_s = re.compile('<span class = "user-stars allstar(.*?)rating"')
p = re.findall(pattern_s,r.text)
s = 0
for star in p:
    s+=int(star)
print(s)

import requests
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'}
r = requests.get('https://book.douban.com/subject/4913064/comments/',headers=headers)